﻿/*
Copyright (c) 2008 Martin Legris

Permission is hereby granted, free of charge, to any person obtaining a copy of this 
software and associated documentation files (the "Software"), to deal in the Software 
without restriction, including without limitation the rights to use, copy, modify, 
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the following 
conditions:

The above copyright notice and this permission notice shall be included in all copies 
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ignore
*/
package newcommerce.lastfm.api.data 
{
	import newcommerce.lastfm.api.feeds.LFMImageFeed;
	import newcommerce.lastfm.api.feeds.LFMTagFeed;
	
	/**
	 * Object containing the complete Album info returned by api method album.getInfo
	 * @author Martin Legris ( http://blog.martinlegris.com )
	 */
	public class LFMAlbumInfo 
	{
		protected var _name:String;
		protected var _artist:String;
		protected var _id:Number;
		protected var _mbid:String;
		protected var _url:String;
		protected var _releaseDate:Date;
		protected var _images:LFMImageFeed;
		protected var _listeners:Number;
		protected var _playCount:Number;
		protected var _topTags:LFMTagFeed;
		
		/**
		 * Name of the album
		 */
		public function get name():String { return _name; }		
		
		/**
		 * Name of the artist
		 */
		public function get artist():String { return _artist; }		
		
		/**
		 * Id of the album on LastFM
		 */
		public function get id():Number { return _id; }		
		
		/**
		 * Music Brainz Id for this album
		 */
		public function get mbid():String { return _mbid; }		
		
		/**
		 * URL for the album on the LastFM website
		 */
		public function get url():String { return _url; }	
		
		/**
		 * The release date of the album
		 */
		public function get releaseDate():Date { return _releaseDate; }		
		
		/**
		 * Feed of images (small, medium, big) for this album
		 */
		public function get images():LFMImageFeed { return _images; }		
		
		/**
		 * The amount of people recorded by LastFM Scrobbling as listening to the album
		 */
		public function get listeners():Number { return _listeners; }		
		
		/**
		 * The amount of time the album was played (as recorded by LastFM Scrobbling)
		 */
		public function get playCount():Number { return _playCount; }		
		
		/**
		 * The most popular tags describing this album
		 */
		public function get topTags():LFMTagFeed { return _topTags; }	
		
		public function LFMAlbumInfo() 
		{
			
		}
		
		/**
		 * Function used to convert the XML structure returned by LastFM's webservice to the data object
		 * @param	xml the XML data given by LastFM's webservice to describe a particular Album
		 * @return LFMAlbumInfo - a data object containing all properties used by LastFM to describe the album
		 */
		public static function fromXML(xml:XML):LFMAlbumInfo
		{
			var data:LFMAlbumInfo = new LFMAlbumInfo();
			data._name = xml.name.toString();
			data._artist = xml.artist.toString();
			data._id = parseInt(xml.id.toString());
			data._mbid = xml.mbid.toString();
			data._url = xml.url.toString();
			data._releaseDate = new Date(Date.parse(xml.releasedate.toString()));
			data._images = new LFMImageFeed(xml.images);
			data._listeners = parseInt(xml.listeners.toString());
			data._playCount = parseInt(xml.playCount.toString());
			data._topTags = new LFMTagFeed(xml.toptags[0]);
			
			return data;
		}
	}
}